/**
 * Copyright (C) 2014 xspace app Project.
 */

package com.xspace.android.imcommon.utils;

import android.content.Context;
import android.os.PowerManager;
import android.provider.Settings;

/**
 * @ClassName: WakeLockManager
 * @author:mawen
 * @Date：2014-2-21
 * @version V1.0.0
 * @Description: TODO
 */
public class WakeLockManager {
	private static PowerManager.WakeLock wl;

	/**
	 * @Description: 获取屏保锁
	 * @param @param context 
	 * @return 
	 * @throws
	 */
	public static void acquireWakeLock(Context context) {
		PowerManager pm = (PowerManager) context
				.getSystemService(Context.POWER_SERVICE);
		wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ClientService");
		wl.acquire();

		Settings.System.putInt(context.getContentResolver(),
				Settings.System.WIFI_SLEEP_POLICY,
				Settings.System.WIFI_SLEEP_POLICY_NEVER);
	}

	/**
	 * @Description: 释放锁
	 * @param  
	 * @return 
	 * @throws
	 */
	public static void releaseWakeLock() {
		if (wl != null && wl.isHeld())
			wl.release();
	}
}
